<?php

/**
* 控制台
*
* @package		Hooloo framework
* @author 		Bill
* @copyright 	Hooloo Co.,Ltd
* @version		1.0
* @release		2017.05.08
*/
defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends Controller{
	public function __construct(){
		parent::__construct();
	}
	
	/**
     * 控制台
     */
	public function index() {
		$this->display();
	}

    /**
     * app升级
     */
    public function app_version()
    {
        $list['app_version']  = config('app_version');
        $list['app_download'] = config('app_download');
        $list['app_info']     = config('app_info');
        ajaxmsg('软件升级',1,$list);
    }


	/*
	 * 轮播图
	 */
	public function slider(){
	    $map['status'] = 1;
	    $sql = "select * from slider";
        $slider = $this->db->query($sql)->result_array();
        ajax_return(1,'',$slider);
    }

    /*
     * 文章中心
     * */
    public function article(){
        $model = $_POST['model'];
        $cid = $_POST['cid'];
        $sql = "select id,title from document where model = $model";
        $article = $this->db->query($sql)->result_array();
        ajax_return($article);
    }

    /*
     * market_bat 批量实时行情接口函数
     * 可通过get或post方式访问返回json格式数据
     * @code 必传参数 多个股票代码，代码间用逗号隔开 如果查询上证指数需要用sh000001
     */
    public function market()
    {
        $data = getParam();
        $code = $data['code'];
        $uid = MID;
        if ($code === null) {
            ajax_return(0,'请搜索股票',null);
        }
        $data = z_market($code);
        if (!$data) {
            ajax_return(0,'操作失败',$data);
        }
        $sub = Db::name('stock_subaccount_self')
            ->where('uid='.$uid)
            ->where('gupiao_code='.$code)
            ->find();
        if (!empty($sub)){
            $data['sub'] = 1;
        }else{
            $data['sub'] = 0;
        }
        $p_range = $data['currency'] - $data['yesterday_price'];
        $data['price_range'] = round($p_range,2);
        $data['price_rate'] = round(($p_range/$data['yesterday_price']*100),2);
        ajax_return(1,'操作成功',$data);
    }

    /*
     * market_bat 批量实时行情接口函数
     * 可通过get或post方式访问返回json格式数据
     * @code 必传参数 多个股票代码，代码间用逗号隔开 如果查询上证指数需要用sh000001
     */
    public function market_bat()
    {
        $code = $_GET['code'];
        if (empty($code)) {
            ajax_return(0,'缺少参数code，操作失败',null);
        }
        $data = z_market_bat($code);
        if (!$data) {
            ajax_return(0,'操作失败',$data);
        }
        foreach($data as $k=>$v){
            $now = z_market($v['code']);
            $p_range = $now['currency'] - $now['yesterday_price'];
            $data[$k]['price_range'] = round($p_range,2);
            $data[$k]['price_rate'] = round(($p_range/$now['yesterday_price']*100),2);
        }
        ajax_return(1,'操作成功',$data);
//        return json(['data' => $data, 'status' => 1, 'message' => '操作成功']);
    }

}
